
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JCheckBox;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author MAGSAKAY
 */
public class Local extends javax.swing.JFrame implements ActionListener{

    /**
     * Creates new form Local
     */
    public Local() {
        initComponents();
        
    }
    String user;
    public Local(String user) {
        this.user=user;
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cbox1 = new javax.swing.JCheckBox();
        cbox2 = new javax.swing.JCheckBox();
        cbox3 = new javax.swing.JCheckBox();
        cbox4 = new javax.swing.JCheckBox();
        cbox5 = new javax.swing.JCheckBox();
        cbox6 = new javax.swing.JCheckBox();
        cbox7 = new javax.swing.JCheckBox();
        cbox8 = new javax.swing.JCheckBox();
        cbox9 = new javax.swing.JCheckBox();
        cbox10 = new javax.swing.JCheckBox();
        cbox11 = new javax.swing.JCheckBox();
        cbox12 = new javax.swing.JCheckBox();
        cbox13 = new javax.swing.JCheckBox();
        cbox14 = new javax.swing.JCheckBox();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        cboMayor = new javax.swing.JComboBox();
        cboViceMayor = new javax.swing.JComboBox();
        cbox16 = new javax.swing.JCheckBox();
        cbox15 = new javax.swing.JCheckBox();
        cbox17 = new javax.swing.JCheckBox();
        cbox18 = new javax.swing.JCheckBox();
        cbox19 = new javax.swing.JCheckBox();
        cbox20 = new javax.swing.JCheckBox();
        cbox21 = new javax.swing.JCheckBox();
        cbox22 = new javax.swing.JCheckBox();
        cbox24 = new javax.swing.JCheckBox();
        cbox23 = new javax.swing.JCheckBox();
        cbox27 = new javax.swing.JCheckBox();
        cbox28 = new javax.swing.JCheckBox();
        cbox25 = new javax.swing.JCheckBox();
        cbox26 = new javax.swing.JCheckBox();
        cbox29 = new javax.swing.JCheckBox();
        cbox31 = new javax.swing.JCheckBox();
        cbox30 = new javax.swing.JCheckBox();
        cbox34 = new javax.swing.JCheckBox();
        cbox35 = new javax.swing.JCheckBox();
        cbox32 = new javax.swing.JCheckBox();
        cbox33 = new javax.swing.JCheckBox();
        jButton2 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        cboGovernor = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        cboViceGovernor = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        cboCongressman = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
        });
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        cbox1.setText("jCheckBox5");

        cbox2.setText("jCheckBox6");

        cbox3.setText("jCheckBox7");

        cbox4.setText("jCheckBox8");

        cbox5.setText("jCheckBox9");

        cbox6.setText("jCheckBox10");

        cbox7.setText("jCheckBox11");

        cbox8.setText("jCheckBox12");

        cbox9.setText("jCheckBox13");

        cbox10.setText("jCheckBox14");

        cbox11.setText("jCheckBox15");

        cbox12.setText("jCheckBox16");

        cbox13.setText("jCheckBox17");

        cbox14.setText("jCheckBox18");

        jButton1.setText("Next");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Georgia", 1, 18)); // NOI18N
        jLabel1.setText("Mayor");

        jLabel2.setFont(new java.awt.Font("Georgia", 1, 18)); // NOI18N
        jLabel2.setText("Vice Mayor");

        jLabel3.setFont(new java.awt.Font("Georgia", 1, 18)); // NOI18N
        jLabel3.setText("Councilors");

        cboMayor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cboMayor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboMayorActionPerformed(evt);
            }
        });

        cboViceMayor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cbox16.setText("jCheckBox13");

        cbox15.setText("jCheckBox12");

        cbox17.setText("jCheckBox14");

        cbox18.setText("jCheckBox15");

        cbox19.setText("jCheckBox16");

        cbox20.setText("jCheckBox17");

        cbox21.setText("jCheckBox18");

        cbox22.setText("jCheckBox12");

        cbox24.setText("jCheckBox14");

        cbox23.setText("jCheckBox13");

        cbox27.setText("jCheckBox17");

        cbox28.setText("jCheckBox18");

        cbox25.setText("jCheckBox15");

        cbox26.setText("jCheckBox16");

        cbox29.setText("jCheckBox12");

        cbox31.setText("jCheckBox14");

        cbox30.setText("jCheckBox13");

        cbox34.setText("jCheckBox17");

        cbox35.setText("jCheckBox18");

        cbox32.setText("jCheckBox15");

        cbox33.setText("jCheckBox16");

        jButton2.setText("Cancel");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel4.setText("jLabel4");

        jLabel5.setFont(new java.awt.Font("Georgia", 1, 18)); // NOI18N
        jLabel5.setText("Governor ");

        cboGovernor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel6.setFont(new java.awt.Font("Georgia", 1, 18)); // NOI18N
        jLabel6.setText("Vice-Gov");

        cboViceGovernor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel7.setFont(new java.awt.Font("Georgia", 1, 18)); // NOI18N
        jLabel7.setText("Congressman");

        cboCongressman.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cbox14)
                                    .addComponent(cbox13)
                                    .addComponent(cbox12)
                                    .addComponent(cbox11)
                                    .addComponent(cbox10)
                                    .addComponent(cbox9)
                                    .addComponent(cbox8))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(cbox1)
                                            .addComponent(cbox2)
                                            .addComponent(cbox3)
                                            .addComponent(cbox4)
                                            .addComponent(cbox5)
                                            .addComponent(cbox6)
                                            .addComponent(cbox7))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(cbox21)
                                            .addComponent(cbox20)
                                            .addComponent(cbox19)
                                            .addComponent(cbox18)
                                            .addComponent(cbox17)
                                            .addComponent(cbox16)
                                            .addComponent(cbox15)))
                                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(cbox28)
                                            .addComponent(cbox27)
                                            .addComponent(cbox26)
                                            .addComponent(cbox25)
                                            .addComponent(cbox24)
                                            .addComponent(cbox23)
                                            .addComponent(cbox22))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(cbox35)
                                            .addComponent(cbox34)
                                            .addComponent(cbox33)
                                            .addComponent(cbox32)
                                            .addComponent(cbox31)
                                            .addComponent(cbox30)
                                            .addComponent(cbox29)))
                                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(cboGovernor, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(cboMayor, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(173, 173, 173)
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(44, 44, 44)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel2)
                            .addComponent(cboViceMayor, 0, 164, Short.MAX_VALUE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cboViceGovernor, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(78, 78, 78)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cboCongressman, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(157, 157, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cboGovernor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboViceGovernor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2))
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cboCongressman, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cboMayor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cboViceMayor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(49, 49, 49)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(cbox1)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox2)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox3)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox4)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox5)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox6)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox7))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(cbox15)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox16)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox17)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox18)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox19)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox20)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox21))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(cbox8)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox9)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox10)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox11)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox12)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox13)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(cbox14)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cbox22)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cbox23)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cbox24)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cbox25)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cbox26)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cbox27)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cbox28))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cbox29)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cbox30)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cbox31)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cbox32)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cbox33)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cbox34)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cbox35)))
                        .addGap(0, 90, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(45, 45, 45))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    public JCheckBox checks[];
    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_formMouseClicked

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        getViceMayors();
        getMayors();
        getGovernors();
        getViceGovernors();
        getCongressman();
        checks = new JCheckBox[]{cbox1,cbox2,cbox3,cbox4,cbox5,cbox6,cbox7,cbox8,cbox9,cbox10,
            cbox11,cbox12,cbox13,cbox14,cbox15,cbox16,cbox17,cbox18,cbox19,cbox20,
        cbox21,cbox22,cbox23,cbox24,cbox25,cbox26,cbox27,cbox28,cbox29,cbox30,
        cbox31,cbox32,cbox33,cbox34,cbox35};
        getCouncilors();
        getAvailableCouncilors();
         for (JCheckBox c:checks)
        {
            c.addActionListener(this);
        }
    }//GEN-LAST:event_formWindowOpened

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
      //  submitVote();
        this.setVisible(false);
        National national = new National(this);
        national.setVisible(true);
        
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
       this.setVisible(false);
       Login login = new Login();
       login.setVisible(true);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void cboMayorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboMayorActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cboMayorActionPerformed
    void submitVote()
    {
        String selectedMayor = mayors[cboMayor.getSelectedIndex()];
        String selectedVice = viceMayors[cboViceMayor.getSelectedIndex()];
        String selectedGovernor = governors[cboGovernor.getSelectedIndex()];
        String selectedViceGovernor = viceGovernors[cboViceGovernor.getSelectedIndex()];
        String selectedCongressman = congressmans[cboCongressman.getSelectedIndex()];
        
        ArrayList<String> selectedCouncilors = new ArrayList();
        for (int i = 0; i < councilors.length; i++) {
            if (checks[i].isSelected())
                selectedCouncilors.add(councilors[i]);
        }
        int currentVote = Utility.getSoleInteger("select * from tblCandidate where username ='"+selectedMayor+"'","votes");
        String sql = "Update tblcandidate set votes="+ (currentVote+1)+" where username = '"+selectedMayor+"'";
        Utility.Save(sql+ "  AND POSITION = 'Mayor' limit 1",false);
        currentVote = Utility.getSoleInteger("select * from tblCandidate where username ='"+selectedVice+"'","votes");
        sql = "Update tblcandidate set votes="+ (currentVote+1)+" where username = '"+selectedVice+"' ";
        Utility.Save(sql+ " AND POSITION = 'Vice Mayor' limit 1",false);
        //
        currentVote = Utility.getSoleInteger("select * from tblCandidate where username ='"+selectedGovernor+"'","votes");
        sql = "Update tblcandidate set votes="+ (currentVote+1)+" where username = '"+selectedGovernor+"' ";
        Utility.Save(sql+ " AND POSITION = 'Governor' limit 1",false);
        
        currentVote = Utility.getSoleInteger("select * from tblCandidate where username ='"+selectedViceGovernor+"'","votes");
        sql = "Update tblcandidate set votes="+ (currentVote+1)+" where username = '"+selectedViceGovernor+"' ";
        Utility.Save(sql+ " AND POSITION = 'Vice-Governor' limit 1",false);
        
        currentVote = Utility.getSoleInteger("select * from tblCandidate where username ='"+selectedCongressman+"'","votes");
        sql = "Update tblcandidate set votes="+ (currentVote+1)+" where username = '"+selectedCongressman+"' ";
        Utility.Save(sql+ " AND POSITION = 'Congressman' limit 1",false);
        
        //
        for (String currCouncilor:selectedCouncilors)
        {
            currentVote = Utility.getSoleInteger("select * from tblCandidate where username ='"+currCouncilor+"'","votes");
            sql = "Update tblcandidate set votes="+ (currentVote+1)+" where username = '"+currCouncilor+"'";
            Utility.Save(sql+ "  AND POSITION = 'City Councilor' limit 1",false);
        }
        sql="Update tblvoter set local = 1 where username = '"+user+"'";
        Utility.Save(sql, false);
    }
    /**
     * @param args the command line arguments
     */
    String mayors[] = new String[0];
    public void getMayors()
    {
        String sql = "Select concat(v.fname, ' ',v.mname,' ',v.lname) as name, v.username"
                + " from tblvoter as v inner join tblcandidate as c where c.position='Mayor' and"
                + " v.username = c.username";
        this.cboMayor.setModel(new javax.swing.DefaultComboBoxModel(Utility.getStrings(sql, "name")));
        mayors = Utility.getStrings(sql, "username");
    }
    String viceMayors[] = new String[0];
    public void getViceMayors()
    {
        String sql = "Select concat(v.fname, ' ',v.mname,' ',v.lname) as name, v.username"
                + " from tblvoter as v inner join tblcandidate as c where c.position='Vice Mayor' and"
                + " v.username = c.username";
        this.cboViceMayor.setModel(new javax.swing.DefaultComboBoxModel(Utility.getStrings(sql, "name")));
        viceMayors = Utility.getStrings(sql, "username");
    }
    String councilors[];
    void getCouncilors()
    {
        String sql = "Select concat(v.fname, ' ',v.mname,' ',v.lname) as name, v.username"
                + " from tblvoter as v inner join tblcandidate as c where c.position='City Councilor' and"
                + " v.username = c.username";
        councilors = Utility.getStrings(sql, "username");
        String[] councilorsName = Utility.getStrings(sql, "name");
        int i =0;
        System.out.println(councilorsName.length);
        boolean firstTime = true;
        if (councilorsName[0].equals(""))
            councilorsName = new String[0];
        for (String name:councilorsName) {
            checks[i].setText(name);
            checks[i].show();
            i++;
        }
        for (int j = i; j < 35; j++) {
            checks[j].hide();
        }
    }
     int available =8;
    void getAvailableCouncilors()
    {
        int x= 0;
        for (JCheckBox c:checks)
        {
            if (c.isSelected())
                x++;
        }
        available = 8 - x;
        if (x>8)x=8;
        String s = "Choose 8. Remaining choices ("+x+"/8)";
        jLabel4.setText(s);
        jLabel4.setForeground(Color.RED);
    }
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Local.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Local.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Local.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Local.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Local().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JComboBox cboCongressman;
    public javax.swing.JComboBox cboGovernor;
    public javax.swing.JComboBox cboMayor;
    public javax.swing.JComboBox cboViceGovernor;
    public javax.swing.JComboBox cboViceMayor;
    private javax.swing.JCheckBox cbox1;
    private javax.swing.JCheckBox cbox10;
    private javax.swing.JCheckBox cbox11;
    private javax.swing.JCheckBox cbox12;
    private javax.swing.JCheckBox cbox13;
    private javax.swing.JCheckBox cbox14;
    private javax.swing.JCheckBox cbox15;
    private javax.swing.JCheckBox cbox16;
    private javax.swing.JCheckBox cbox17;
    private javax.swing.JCheckBox cbox18;
    private javax.swing.JCheckBox cbox19;
    private javax.swing.JCheckBox cbox2;
    private javax.swing.JCheckBox cbox20;
    private javax.swing.JCheckBox cbox21;
    private javax.swing.JCheckBox cbox22;
    private javax.swing.JCheckBox cbox23;
    private javax.swing.JCheckBox cbox24;
    private javax.swing.JCheckBox cbox25;
    private javax.swing.JCheckBox cbox26;
    private javax.swing.JCheckBox cbox27;
    private javax.swing.JCheckBox cbox28;
    private javax.swing.JCheckBox cbox29;
    private javax.swing.JCheckBox cbox3;
    private javax.swing.JCheckBox cbox30;
    private javax.swing.JCheckBox cbox31;
    private javax.swing.JCheckBox cbox32;
    private javax.swing.JCheckBox cbox33;
    private javax.swing.JCheckBox cbox34;
    private javax.swing.JCheckBox cbox35;
    private javax.swing.JCheckBox cbox4;
    private javax.swing.JCheckBox cbox5;
    private javax.swing.JCheckBox cbox6;
    private javax.swing.JCheckBox cbox7;
    private javax.swing.JCheckBox cbox8;
    private javax.swing.JCheckBox cbox9;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    // End of variables declaration//GEN-END:variables

    @Override
    public void actionPerformed(ActionEvent ae) {
         Object source = ae.getSource();
       getAvailableCouncilors();
       for (JCheckBox c:checks)
       {
         if (c == source)
         {
             if (available==-1)
             {
                 c.setSelected(false);
             }
         }
       }
    }
    //
    String governors[] = new String[0];
    public void getGovernors()
    {
        String sql = "Select concat(v.fname, ' ',v.mname,' ',v.lname) as name, v.username"
                + " from tblvoter as v inner join tblcandidate as c where c.position='Governor' and"
                + " v.username = c.username";
        this.cboGovernor.setModel(new javax.swing.DefaultComboBoxModel(Utility.getStrings(sql, "name")));
        governors = Utility.getStrings(sql, "username");
    }
    String congressmans[] = new String[0];
    public void getCongressman()
    {
        String sql = "Select concat(v.fname, ' ',v.mname,' ',v.lname) as name, v.username"
                + " from tblvoter as v inner join tblcandidate as c where c.position='Congressman' and"
                + " v.username = c.username";
        this.cboCongressman.setModel(new javax.swing.DefaultComboBoxModel(Utility.getStrings(sql, "name")));
        congressmans = Utility.getStrings(sql, "username");
    }
    String viceGovernors[] = new String[0];
    public void getViceGovernors()
    {
        String sql = "Select concat(v.fname, ' ',v.mname,' ',v.lname) as name, v.username"
                + " from tblvoter as v inner join tblcandidate as c where c.position='Vice-Governor' and"
                + " v.username = c.username";
        this.cboViceGovernor.setModel(new javax.swing.DefaultComboBoxModel(Utility.getStrings(sql, "name")));
        viceGovernors = Utility.getStrings(sql, "username");
    }
}
